<?php
  /*
 * php-rss-parser - RSS Parser
 * @copyright Kivanc Erten <kivancerten@gmail.com>
 * @author Kivanc Erten <kivancerten@gmail.com>
 * @version 0.1
 * @license GNU GPL v3
 */
 
class php_rss_parser {

	private $URL;
	private $XMLText;
	private $Properties;
	private $Items;

	public function SetURL($URL) {
		$this->URL = $URL;
	}

	private function GetRemoteXML() {
		$this->XMLText = file_get_contents($this->URL);
	}

	public function GetProperties() {
		return $this->Properties;
	}

	public function GetItems() {

		$this->GetRemoteXML();

		$XMLObject = new SimpleXMLElement($this->XMLText,LIBXML_NOCDATA);
		$XMLObject->getNamespaces(true);

		if (!isset($XMLObject->channel)) return false;

		if (isset($XMLObject->channel->item)) {
			if (count($XMLObject->channel->item)) foreach ($XMLObject->channel->item as $Item) {
				$Elements = get_object_vars($Item);

				$dc = $Item->children('http://purl.org/dc/elements/1.1/');
				$dc = get_object_vars($dc);
				foreach($dc as $dc_key => $dc_item) {
					$Elements[$dc_key] = $dc_item;
				}

				$this->Items[] = $Elements;
			}
			unset($XMLObject->channel->item);
		}
		$this->Properties = get_object_vars($XMLObject->channel);

		return $this->Items;
	}

}
